package com.swak.frame.api.filter.extension;

import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.google.common.base.Splitter;
import com.google.common.collect.Sets;
import com.swak.frame.config.ConfigCenterAdapter;
import com.swak.frame.extension.annotation.Extension;
import com.swak.frame.extension.provider.RiskWhiteListExtPtProvider;
import com.swak.frame.util.EmptyObject;

@Extension(desc = "风控白名单")
public class DefaultRiskWhiteListProducer implements RiskWhiteListExtPtProvider {

	@Autowired(required = false)
	private ConfigCenterAdapter configCenterAdapter;

	@Override
	public Set<String> whiteListConfig() {
		if (configCenterAdapter == null) {
			return EmptyObject.emptySet();
		}
		String whiteList = configCenterAdapter.getString(RISK_WHITE_LIST);
		if (StringUtils.isEmpty(whiteList)) {
			return EmptyObject.emptySet();
		}
		return Sets.newHashSet(Splitter.on(',').splitToList(whiteList));
	}
}
